package com.greensecurity.sim.service.impl;

import com.greensecurity.sim.entity.User;
import com.greensecurity.sim.repository.UserRepository;
import com.greensecurity.sim.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class UserServiceImpl  implements UserService {

    @Resource
    private UserRepository userRepository;

    @Override
    public User findByUserName(String getMapByName) {
        return userRepository.findByUserName(getMapByName);
    }

    @Override
    public User findByPhone(String phone) {
        return userRepository.findByPhone(phone);
    }

    @Override
    public String save(User user) {
        userRepository.save(user);
        return "保存成功";
    }

    @Override
    public Optional<User> findById(Long id) {
        return userRepository.findById(id);
    }

    @Override
    public String selectRoleUserNum(String id){
        return userRepository.selectAdminOrWaringOrInsectUserNum(id);
    }
    @Override
    public Integer selectAllUserNum(){
        log.info("走了这里");
        return userRepository.selectAllUserNum();
    }
    @Override
    public List<User> findAll(){
        return userRepository.findAll();
    }

    @Override
    public String del(User user) {
        userRepository.delete(user);
        return "删除成功";
    }
}
